-
-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Machine translation of posts #4307
Conversation
app/build.gradle
Outdated
@@ -40,6 +40,13 @@ android { | |||
buildConfigField("String", "CUSTOM_INSTANCE", "\"$CUSTOM_INSTANCE\"") | |||
buildConfigField("String", "SUPPORT_ACCOUNT_URL", "\"$SUPPORT_ACCOUNT_URL\"") | |||
} | |||
compileOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fixed my IDE but idk if we should remove it before the release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't even merge it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the blessed way now is
kotlin {
jvmToolchain(17)
}
40f8cbb
to
c2fef72
Compare
@connyduck bitrise failed for no apparent reason |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable. I've installed it locally, but I don't think any of my instances support translation 😐
app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt
Outdated
Show resolved
Hide resolved
|
||
val translateItem = menu.findItem(R.id.status_translate) | ||
translateItem.isVisible = | ||
onMoreTranslate != null && status.language != Locale.getDefault().language && instanceInfoRepository.getCachedInstanceInfoOrFallback().translationEnabled == true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fetch it here before showing the dropdown but I could also preload it when the screen is opened
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd preload it, otherwise there might be an annoying delay when clicking the more button
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't seem to be a problem a practice but I can preload!
app/.idea/workspace.xml
Outdated
</task> | ||
<servers /> | ||
</component> | ||
</project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this file should be checked in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, was a mistake, slipped in at some point, sorry!
It took me a while to figure out why the menu item was not shown for me, even though m.s supports translation. Turns out instance info is never downloaded again when it is already cached, except when going to About/Compose/EditProfile. That needs to change somehow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works very well 😍
@@ -15,6 +15,9 @@ | |||
<item | |||
android:id="@+id/status_copy_link" | |||
android:title="@string/action_copy_link" /> | |||
<item | |||
android:id="@+id/status_translate" | |||
android:title="Translate" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be translateable
|
||
val translateItem = menu.findItem(R.id.status_translate) | ||
translateItem.isVisible = | ||
onMoreTranslate != null && status.language != Locale.getDefault().language && instanceInfoRepository.getCachedInstanceInfoOrFallback().translationEnabled == true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd preload it, otherwise there might be an annoying delay when clicking the more button
android:layout_marginEnd="4dp" | ||
android:maxLines="4" | ||
android:visibility="gone" | ||
tools:visibility="visible" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused, currently the first line is aligned with the button text, would you rather center it relative to the text? To me both looks good, I will try your idea with centering!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
padding between them, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
padding between them, right?
4dp additional padding between username and text, but of course there should also be a bit of padding between text & button.
idk how to both center the button to the text but also not make button overlap above?
A yes when the text is only one line it can overlap 🤔
Some possibilities:
- another barrier
- force the text to be at least 2 lines
- leave it top aligned
I don't care much.
.onFailure { | ||
status.update() | ||
} | ||
.asResult() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just forward the NetworkResult
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's kind of leaking an impl detail to me but if you think it's useless I can just pass it through
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong opinion about either, you can leave it if you want
.setMessage(R.string.notification_clear_text) | ||
.setPositiveButton(android.R.string.ok, (DialogInterface dia, int which) -> clearNotifications()) | ||
.setNegativeButton(android.R.string.cancel, null) | ||
.show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you maybe remove these indendation changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for sure, sorry!
app/src/main/res/values/strings.xml
Outdated
@@ -211,6 +211,9 @@ | |||
<string name="action_copy_link">Copy the link</string> | |||
<string name="action_open_as">Open as %s</string> | |||
<string name="action_share_as">Share as …</string> | |||
<string name="action_translate">Translate</string> | |||
<string name="action_show_original">Show original</string> | |||
<string name="action_show_untransalted">Show untranslated</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in the name, but also unused?
I've fixed most things (except for the button position). I had to rebase to get |
Thank you for catching those issues with instance cache! |
) : ViewModel() { | ||
|
||
init { | ||
instanceInfoRepository.precache() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like having side-effects in constructor but I don't want to introduce an init()
method either
I believe I have addressed everything except for the build.gradle thing, I can take it out, no problem with that |
We actually wanted to use Java 21 #4235 |
oh I see |
translateItem.isVisible = | ||
onMoreTranslate != null && status.language != Locale.getDefault().language && instanceInfoRepository.cachedInstanceInfoOrFallback.translationEnabled == true | ||
translateItem.setTitle(if (translation != null) R.string.action_show_original else R.string.action_translate) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting this one when opening the menu for one of my own posts from the detailed view - not sure if we need to nullcheck or otherwise guard the menu item visibility logic
Process: com.keylesspalace.tusky.test, PID: 4953
java.lang.NullPointerException: Attempt to invoke interface method 'android.view.MenuItem android.view.MenuItem.setVisible(boolean)' on a null object reference
at com.keylesspalace.tusky.fragment.SFragment$more$1.invokeSuspend(SFragment.kt:221)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:363)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:21)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:88)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:123)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:52)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:43)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
at com.keylesspalace.tusky.fragment.SFragment.more(SFragment.kt:157)
at com.keylesspalace.tusky.components.viewthread.ViewThreadFragment.onMore(ViewThreadFragment.kt:377)
at com.keylesspalace.tusky.adapter.StatusBaseViewHolder.lambda$setupButtons$11(StatusBaseViewHolder.java:717)
at com.keylesspalace.tusky.adapter.StatusBaseViewHolder.$r8$lambda$2lpNa1dIlwqMDFIdAYaiyDBB3A4(Unknown Source:0)
at com.keylesspalace.tusky.adapter.StatusBaseViewHolder$$ExternalSyntheticLambda9.onClick(D8$$SyntheticClass:0)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access$3600(View.java:810)
at android.view.View$PerformClick.run(View.java:28305)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish we just made the menus programmatically
- it is not inflated for user's own posts but we didn't check for that - some servers return language codes in uppercase and it wasn't matching Java's lowercase code when it should have
fixed the crash, fixed another issue with language code comparison, rebased again |
@connyduck & @charlag was there some fix for the instance caching issue? Perhaps I missed it but this will work with instances using either DeepL or LibreTranslate right? I'm not seeing the option to translate posts like I do on Megalodon. |
Unfortunately not working for me, I get an error "Required value 'mediaAttachments' ([...]) missing" when trying to translate a post. Running mastodon 4.1.15 |
@smiba Can you give me more details please? Which status are you translating into which language from which mastodon server? |
I forgot which status, but they all behave the same and respond with an error. I think it was Japanese into English though. It's from the mastodon server I manage: https://woof.tech -- We're running an older version (4.1.15) of Mastodon with backported changes. Not sure if this issue is with all 4.1 instances but I'd imagine so? I haven't made any changes to it's translation API or translation functionality in general If there is anything else I can do please let me know, couldn't quickly figure out if I could dump Tusky's logs from my phone without adb etc. |
@smiba Unfortunately it is not possible to create an account. Clicking the confirmation link shows this screen and the resend does nothing: Why you don't upgrade to 4.2? |
Sorry, should be resolved now! We're running some patches that I've yet to migrate to 4.2, which means we're currently stuck on 4.1. I hope to finally have time soon to migrate everything to 4.2 |
Thank you 💜 |
…on some servers (#4422) see #4307 (comment)
…on some servers (#4422) see #4307 (comment)
No description provided.